import org.apache.commons.codec.digest.DigestUtils as DU


class BootStrap {


     def init = { servletContext ->

         def computer = new Category(title:"Accounting", parent:null)
         computer.save()
         def education = new Category(title:"Academic/Education/Training", parent:null)
         education.save()
         //new Category(title:"Administrative").save()
         def health = new Category(title:"Healthcare", parent:null)
         health.save()
         def adminstration =  new Category(title:"Administration", parent:null)
         adminstration.save()

//         new Category(title:"Human Resource").save()
//         new Category(title:"Logistics").save()
//         new Category(title:"Sales/Marketing").save()
         new Category(title:"Computer Services", parent:computer).save()
         new Category(title:"Computer Hardware", parent:computer).save()
         new Category(title:"Computer Software", parent:computer).save()
         new Category(title:"Creative Design", parent:computer).save()
         new Category(title:"Internet/Ecommerce",parent:computer).save()
         new Category(title:"IT/Software developpement", parent:computer).save()
         def java = new Category(title:"Java developper", parent:computer)
         java.save()
         new Category(title:"C++/.Net developper", parent:computer).save()
//         new Category(title:"Electronics").save()
//         new Category(title:"Employement placement agencies").save()
         new Category(title:"Finace/Economics", parent:adminstration).save()
         new Category(title:"Insurance", parent:adminstration).save()
         new Category(title:"Human Ressources", parent:adminstration).save()

		def usrRole = new Authority(authority:"ROLE_USER",description:"User role")
        usrRole.save()
		def moderatorRole = new Authority(authority:"ROLE_MODERATOR",description:"Moderator role")
         moderatorRole.save()
		def adminRole = new Authority(authority:"ROLE_ADMINISTRATOR",description:"Administrator role")
		adminRole.save()
		def suspendedRole = new Authority(authority:"ROLE_SUSPENDED",description:"Suspended role")
        suspendedRole.save()
        def supervisorRole = new Authority(authority:"ROLE_SUPERVISOR",description:"Supervisor role")
        supervisorRole.save()
//         def userRole = new Authority(authority:"ROLE_USER",description:"User role")
//         userRole.save()

//         new Requestmap(url:"/**", configAttribute:"IS_AUTHENTICATED_ANONYMOUSLY").save()
//         new Requestmap(url:"/requestmap/**",configAttribute:"ROLE_SUPERVISOR,ROLE_ADMINISTRATOR").save()
         new Requestmap(url:"/user/show/**",configAttribute:"ROLE_USER,ROLE_ADMINISTRATOR").save()
         new Requestmap(url:"/user/list/**",configAttribute:"ROLE_USER,ROLE_ADMINISTRATOR").save()
         new Requestmap(url:"/user/update/**",configAttribute:"ROLE_USER,ROLE_ADMINISTRATOR").save()
         new Requestmap(url:"/content/create/**",configAttribute:"ROLE_USER,ROLE_ADMINISTRATOR").save()
         new Requestmap(url:"/content/edit/**",configAttribute:"ROLE_USER,ROLE_ADMINISTRATOR").save()
//        new Requestmap(url:"/memberprofile/**",configAttribute:"ROLE_USER,ROLE_ADMINISTRATOR").save()
//        new Requestmap(url:"/category/**",configAttribute:"ROLE_USER,ROLE_ADMINISTRATOR").save()


        def profile = new MemberProfile()
         profile.save()
         println "Empty Profile created : " + profile?.id
         def admin = new Person(username:"admin",
                 userRealName:"System admin",
                 email:"admin@syste.com",
                 passwd:"${DU.md5Hex("ahlan123")}",
                 enabled:true,
                 email_show:true,
                 description:"This user rocks.",
                 //gender:"Male",
                 state:"Quebec",
                 country:"Canada",
                 zipCode:"H3T1G1", referedBy:null
         ,profile:profile)
         admin.save()
         admin.addToAuthorities(usrRole)
         admin.addToAuthorities(moderatorRole)
         admin.addToAuthorities(adminRole)

         def bahaUser = new Person(username:"baha",
                 userRealName:"Bahaiddine Abu Shaaban",
                 email:"abshaaban@syste.com",
                 passwd:"${DU.md5Hex("ahlan123")}",
                 enabled:true,
                 email_show:true,
                 description:"This user rocks.",
                 //gender:"Male",
                 state:"Quebec",
                 country:"Canada",
                 zipCode:"H3T1G1", referedBy:admin
         ,profile:profile)
             bahaUser.save()
          bahaUser.addToAuthorities(usrRole)
          bahaUser.addToAuthorities(moderatorRole)

             def oussamaUser = new Person(username:"oussama",
                 userRealName:"Oussama Azizi",
                 email:"azizio@syste.com",
                 passwd:"${DU.md5Hex("ahlan123")}",
                 enabled:true,
                 email_show:true,
                 description:"IT Developer",
                 //gender:"Male",
                 state:"Quebec",
                 country:"Canada",
                 zipCode:"H3T1G1", referedBy:admin
             ,profile:profile)
             oussamaUser.save()
          oussamaUser.addToAuthorities(usrRole)
          oussamaUser.save()
             def antoineUser = new Person(username:"antoine",
                 userRealName:"Antoine Ferron",
                 email:"ferrona@syste.com",
                 passwd:"${DU.md5Hex("ahlan123")}",
                 enabled:true,
                 email_show:true,
                 description:"IT Developer",
                 //gender:"Male",
                 state:"Quebec",
                 country:"Canada",
                 zipCode:"H3T1G1", referedBy:admin
             ,profile:profile)
             antoineUser.save()


         def list = ["Java", "Modeling"]
         def prof1 = new MemberProfile(title:"Intermidiate Java developper"
                    ,resume:"<b>Intermediate Java Developper</b><br>bla bal bla",
         expertise:list)
         prof1.save()
         prof1.addToCategories(java)

            def karimUser = new Person(username:"karim",
                 userRealName:"Karim Daher",
                 email:"daherk@syste.com",
                 passwd:"${DU.md5Hex("ahlan123")}",
                 enabled:true,
                 email_show:true,
                 description:"IT Developer",
                 //gender:"Male",
                 state:"Quebec",
                 country:"Canada",
                 zipCode:"H3T1G1", referedBy:admin
            ,profile:prof1)
             karimUser.save()
         karimUser.addToAuthorities(usrRole)
         karimUser.save()
println "  >>> KARIM: "+karimUser?.id

         

     }
     def destroy = {
     }
} 